<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>图书借阅系统 - 用户列表</title>
  <!-- 引入 Google Fonts 以使用更现代的字体 -->
  <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
  <style>
    /* 全局样式 */
    body {
      font-family: 'Poppins', sans-serif;
      margin: 0;
      padding: 0;
      background-color: #f4f4f9;
      color: #333;
      background-image: url('https://images.unsplash.com/photo-1507842217343-583bb7270b66');
      background-size: cover;
      background-position: center;
      background-repeat: no-repeat;
      backdrop-filter: blur(5px);
      display: flex;
      flex-direction: column;
      align-items: center;
      min-height: 100vh;
    }

    nav {
      background-color: rgba(44, 62, 80, 0.9);
      overflow: hidden;
      position: fixed;
      top: 0;
      width: 100%;
      z-index: 1000;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
      transition: background-color 0.3s ease;
    }

    nav ul {
      list-style-type: none;
      margin: 0;
      padding: 0;
      display: flex;
      justify-content: center;
    }

    nav ul li {
      margin: 0 10px;
    }

    nav ul li a {
      display: block;
      color: white;
      text-align: center;
      padding: 16px 20px;
      text-decoration: none;
      transition: background-color 0.3s ease, transform 0.3s ease;
      font-size: 16px;
    }

    nav ul li a:hover {
      background-color: #34495e;
      transform: scale(1.05);
    }

    .container {
      padding: 50px 40px 40px 40px;
      max-width: 1200px;
      width: 90%;
      background-color: rgba(255, 255, 255, 0.9);
      border-radius: 15px;
      box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
      margin-top: 50px;
      animation: fadeIn 0.5s ease;
      transition: box-shadow 0.3s ease;
    }

    .container:hover {
      box-shadow: 0 15px 30px rgba(0, 0, 0, 0.3);
    }

    @keyframes fadeIn {
      from {
        opacity: 0;
        transform: translateY(-20px);
      }
      to {
        opacity: 1;
        transform: translateY(0);
      }
    }

    h1 {
      font-size: 3em;
      color: #2c3e50;
      text-align: center;
      margin-top: 20px;
      margin-bottom: 35px;
      text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
      background: -webkit-linear-gradient(45deg, #2c3e50, #007BFF);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
    }

    .search-container {
      margin-top: 20px;
      margin-bottom: 40px;
      display: flex;
      justify-content: center;
      gap: 10px;
    }

    #search-input {
      padding: 15px;
      width: 400px;
      border: 1px solid #ccc;
      border-radius: 8px;
      font-size: 16px;
      transition: border-color 0.3s ease, box-shadow 0.3s ease;
      background-color: rgba(255, 255, 255, 0.8);
    }

    #search-input:focus {
      border-color: #007BFF;
      outline: none;
      box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
    }

    #search-button {
      padding: 15px 30px;
      background-color: #007BFF;
      color: white;
      border: none;
      border-radius: 8px;
      cursor: pointer;
      transition: background-color 0.3s ease, transform 0.3s ease;
      font-size: 16px;
      font-weight: 500;
      box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    }

    #search-button:hover {
      background-color: #0056b3;
      transform: scale(1.05);
    }

    table {
      width: 100%;
      border-collapse: collapse;
      margin-top: 20px;
      overflow: hidden;
      border-radius: 8px;
      box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    }

    table th,
    table td {
      border: none;
      padding: 15px;
      text-align: center;
      transition: background-color 0.3s ease;
    }

    table th {
      background-color: #2c3e50;
      color: white;
      font-weight: bold;
      font-size: 18px;
    }

    table tr:nth-child(even) {
      background-color: #f2f2f2;
    }

    table tr:hover {
      background-color: #e0e0e0;
    }

    table td:nth-child(2) {
      font-weight: bold;
    }

    table td:nth-child(4) {
      color: red;
    }

    table td:nth-child(4)[data-nums="high"] {
      color: green;
    }

  </style>
  <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>

<body>
<nav>
  <ul>
    <li><a href="http://localhost:8888/lib/allbook">图书列表</a></li>
    <li><a href="http://localhost:8888/lib/allborrow">借阅记录</a></li>
    <li><a href="http://localhost:8888/lib/alluser">用户信息</a></li>
    <li><a href="http://localhost:8888/lib/addBook">添加图书</a></li>
    <li><a href="http://localhost:8888/lib/deleteBook">删除图书</a></li>
    <li><a href="http://localhost:8888/api/outLogin">退出</a></li>
  </ul>
</nav>
<div class="container">
  <h1>用户列表</h1>
  <!-- 搜索框和搜索按钮 -->
  <div class="search-container">
    <label for="search-input"></label><input type="text" id="search-input" placeholder="输入用户名进行搜索">
    <button id="search-button">搜索</button>
  </div>
  <table id="book-table">
    <thead>
    <tr>
      <th>card_id</th>
      <th>用户名</th>
      <th>邮箱</th>
      <th>剩余可借阅数量</th>
    </tr>
    </thead>
    <tbody>
    <!-- 用户数据将通过 jQuery 动态加载 -->
    </tbody>
  </table>
</div>
<script>
  $(document).ready(function () {
    // 初始加载用户列表
    loadUsers('null');

    // 搜索按钮点击事件
    $('#search-button').on('click', function () {
      let searchTerm = $('#search-input').val();
      if (searchTerm == null || searchTerm === '') {
        searchTerm = 'null';
      }
      loadUsers(searchTerm);
    });

    // 加载用户列表的函数
    function loadUsers(searchTerm) {
      $.ajax({
        url: `/manager/alluser/${searchTerm}`,
        method: 'GET',
        success: function (R) {
          const data=R.data;
          $('#book-table tbody').empty();
          let num = data.length;
          if (num === 0) {
            alert("没有匹配到您想要的数据，请重试...");
            window.location.reload();
          }
          data.forEach(function (user) {
            let numClass = user.nums > 5? 'high' : '';
            $('#book-table tbody').append(`
                                <tr>
                                    <td>${user.cardId}</td>
                                    <td>${user.username}</td>
                                    <td>${user.email}</td>
                                    <td data-nums="${numClass}">${user.nums}</td>
                                </tr>
                            `);
          });
        },
        error: function () {
          alert('加载用户列表失败');
        }
      });
    }
  });
</script>
</body>

</html>